<?php

class PHPX
{
	public static function GenerateComponent( $XML, $RootComponent = null )
	{
		$Name = $XML->getName( );
		$Component = new $Name( );
		if( $RootComponent == null ) $RootComponent = $Component;
		foreach( $XML->attributes( ) as $Attribute => $Value )
		{
			$Component->$Attribute = (string)$Value;
		}
		foreach( $XML->children( 'http://martiendejong.nl/phpx' ) as $Child )
		{
			$ChildComponent = PHPX::GenerateComponent( $Child, $RootComponent );
			$ChildComponent->Parent = $Component;
			$Component->Children->Add( $ChildComponent );
			if( isset( $ChildComponent->Name ) )
			{
				$ChildName = $ChildComponent->Name;
				$RootComponent->$ChildName = $ChildComponent;
			}
		}
		$Component->XML = $XML;
		$Component->Init( );
		return $Component;
	}

}

?>